**Do file for replication of Bayam, Sledge, and Thomas ISQ
**Correspondence: Herschel Thomas @ herschelfthomas@gmail.com 
**Updated Dec 2023

**Requires data_for_replication_models_dec2023.dta and data_for_replication_state_contacts.dta

clear
*set working directory
cd "/Users/hft00001/Dropbox/Research/covid mayors"

******* Descriptives

*Table 1
clear
use data_for_replication_models_dec2023, replace
sum who_impact_dum info_who_dum pol_idea2 solv_intrnlprobs lost_tax
tab region2 
tab geo_scope 

*Figure A1
clear
use data_for_replication_models_dec2023, replace
contract state
rename _freq survey
joinby state using data_for_replication_state_contacts, unmatched(both)
recode survey (.=0)
recode contact (.=0)
rename contact sample
drop _m
egen survey_total=sum(survey)
egen sample_total=sum(sample)
gen survey_per=(survey/survey_total)*100
gen sample_per=(sample/sample_total)*100
gen diff=survey_per-sample_per
gsort diff
graph dot diff, over(stat, sort((mean) diff) gap(12)) aspect(2.5) ysize(9) yline(0) ytitle("Contact vs. Response Difference") bgcolor(white) graphregion(color(none))
graph export fa1.png, replace
graph export fa1.pdf, replace

*Table A1
clear
use data_for_replication_models_dec2023, replace
contract state
rename _freq survey
joinby state using data_for_replication_state_contacts, unmatched(both)
recode survey (.=0)
recode contact (.=0)
rename contact sample
drop _m
egen survey_total=sum(survey)
egen sample_total=sum(sample)
gen survey_per=(survey/survey_total)*100
gen sample_per=(sample/sample_total)*100
gen diff=survey_per-sample_per
gsort diff
keep state survey_per sample_per diff

*Table A2
clear
use data_for_replication_models_dec2023, replace
tab pol_idea2 party_affiliation

*Figure 1 and Table A3
clear
use data_for_replication_models_dec2023, replace
drop if pol_idea2==.
tab who_impact_dum
tab pol_idea2
keep if pol_idea2!=. & who_impact_dum!=.
tab pol_idea2 who_impact_dum, row
gen counter=1
collapse (sum) who_impact_dum counter, by(pol_idea2)
gen percent=(who_impact_dum/counter)*100
graph hbar (asis) percent, graphregion(color(white)) bgcolor(white) bar(1, fcolor(grey%30) lcolor(black)) over(pol_idea2) ytitle("% 'A lot of/Some' Impact") aspect(1)
graph export f1_desc_who_impact_plot.pdf, replace
graph export f1_desc_who_impact_plot.png, replace

****** Models

*Figures 2-4 and Tables A4-A7

*** Impact DV

*need outreg2 package installed

*Model 1 - DV: Impact, IV: Ideology only
clear
use data_for_replication_models_dec2023, replace
logit who_impact_dum ib6.pol_idea2, or
outreg2 using models_results.doc, replace ctitle(Model 1) dec(2)
margins, at(pol_idea2=(2(1)6))vsquish post
marginsplot, aspect(1) ytitle("Predicted Probability") ylab(0(.2)1) xlab(,angle(45)) title("") legend(pos(bottom)) xtitle("") graphregion(color(white) margin(5 5 0 0)) bgcolor(white) 
graph save margins_plot_model1.gph, replace

*Model 2 - DV: Impact, IV: full, no interaction
clear
use data_for_replication_models_dec2023, replace
logit who_impact_dum ib6.pol_idea2  ib5.solv_intrnlprobs i.region2 i.geo_scope lost_tax, or  
estimates store impact_full
outreg2 using models_results.doc, append ctitle(Model 2) dec(2)
margins, at(pol_idea2=(2(1)6))vsquish post
outreg2 using margins.doc, replace ctitle(Model 2)  dec(2) ci
marginsplot, plot1opts(lcolor(navy%70) lpattern(dash) msymbol(O) mcolor(navy)) ciopt(color(navy%70)) aspect(1) ytitle("Predicted Probability") ylab(0(.2)1) xlab(,angle(45)) xtitle("") title("A. Impact of WHO", pos(11) margin(b=4)) legend(pos(bottom)) graphregion(color(white)) bgcolor(white)
graph save margins_plot_model2.gph, replace

*** Trust DV

*Model 3 - DV: Trust, IV: Ideology only
clear
use data_for_replication_models_dec2023, replace
tab info_who_dum
logit info_who_dum ib6.pol_idea2, or
outreg2 using models_results.doc, append ctitle(Model 3) dec(2)
margins, at(pol_idea2=(2(1)6))vsquish post
marginsplot, plot1opts(lcolor(gs5) msymbol(Oh)) ciopt(color(black%40)) aspect(1) ytitle("Predicted Probability of Trust") ylab(0(.2)1) xlab(,angle(45)) title("") legend(pos(bottom)) xtitle("") legend(pos(bottom)) graphregion(color(white)) bgcolor(white) 
graph save margins_plot_model3.gph, replace

*Model 4 - DV: Trust, IV: full, no interaction
clear
use data_for_replication_models_dec2023, replace
logit info_who_dum ib6.pol_idea2 ib5.solv_intrnlprobs i.region2 i.geo_scope lost_tax, or 
estimates store trust_full
outreg2 using models_results.doc, append ctitle(Model 4) dec(2)
margins, at(pol_idea2=(2(1)6))vsquish post
outreg2 using margins.doc, append ctitle(Model 4) dec(2) ci
marginsplot, plot1opts(lcolor(sienna%70) lpattern(dash) msymbol(D) mcolor(sienna)) ciopt(color(sienna)) aspect(1) ytitle("Predicted Probability") ylab(0(.2)1) xlab(,angle(45)) xtitle("") title("B. Trust of WHO", pos(11) margin(b=4)) legend(pos(bottom)) graphregion(color(white)) bgcolor(white)
graph save margins_plot_model4.gph, replace

*** Interactive Models

*** Impact DV

*Model 5 - DV: Impact, IV: full, interaction Governor partisanship
clear
use data_for_replication_models_dec2023, replace
logit who_impact_dum ib6.pol_idea2##i.gov_dem_dummy ib5.solv_intrnlprobs i.region2 i.geo_scope lost_tax, or  
outreg2 using models_interactive_results.doc, replace ctitle(Model 5) dec(2)
margins, at(gov_dem_dummy=(0(1)1) pol_idea2=(2, 6)) vsquish post
outreg2 using margins_interactive_gov.doc, replace ctitle(Model 5) dec(2) ci
marginsplot, ///
plot1opts(msymbol(D) mcolor("green") lcolor("green") lpattern(dash)) ///
ci1opt(lcolor(green)) ///
plot2opts(msymbol(O) mcolor("maroon")  lcolor("maroon") lpattern(dash)) ///
ci2opt(lcolor("maroon")) ///
aspect(1) ytitle("Predicted Probability") ylab(0(.2)1) title("A. Impact of WHO", pos(11) margin(b=4)) legend(pos(bottom)) xtitle("Governor Partisanship") graphregion(color(white) margin(5 5 0 0)) bgcolor(white) legend(rows(2) region(lstyle(none)))
graph save margins_plot_model5.gph, replace

*Model 6 - DV: Impact, IV: full, interaction Trump vote share
clear
use data_for_replication_models_dec2023, replace
logit who_impact_dum ib6.pol_idea2##c.trump_vote_prop ib5.solv_intrnlprobs i.region2 i.geo_scope lost_tax, or  
outreg2 using models_interactive_results.doc, append ctitle(Model 6) dec(2)
margins, at(trump_vote_prop=(.3(.1).7) pol_idea2=(2, 6)) vsquish post
outreg2 using margins_interactive_trump.doc, replace ctitle(Model 6) dec(2) ci
marginsplot, ///
plot1opts(lcolor(green)) ///
ci1opt(fcolor(green%15) lcolor(green%15) lwidth(0)) ///
plot2opts(lcolor(maroon)) ///
ci2opt(fcolor(maroon%15) lcolor(maroon%15) lwidth(0)) ///
recast(line) recastci(rarea) aspect(1) ytitle("Predicted Probability") xtitle("Trump Vote Share") ylab(0(.2)1) title(" ", pos(11) margin(b=4))   legend(pos(bottom)) graphregion(color(white) margin(5 5 0 0)) bgcolor(white) legend(rows(2) region(lstyle(none)))
graph save margins_plot_model6.gph, replace

*Model 7 - DV: Impact, IV: full, interaction Governor trust
clear
use data_for_replication_models_dec2023, replace
logit who_impact_dum ib6.pol_idea2##i.info_govnr_dum ib5.solv_intrnlprobs i.region2 i.geo_scope lost_tax, or 
outreg2 using models_interactive_results.doc, append ctitle(Model 7) dec(2)
margins, at(info_govnr_dum=(0(1)1) pol_idea2=(2, 6)) vsquish post
outreg2 using margins_interactive_govtrust.doc, replace ctitle(Model 7) dec(2) ci
marginsplot, ///
plot1opts(msymbol(D) mcolor("green") lcolor("green") lpattern(dash)) ///
ci1opt(lcolor(green)) ///
plot2opts(msymbol(O) mcolor("maroon")  lcolor("maroon") lpattern(dash)) ///
ci2opt(lcolor("maroon")) ///
aspect(1) ytitle("Predicted Probability") ylab(0(.2)1) xtitle("Governor Trust") title(" ", pos(11) margin(b=4))  legend(pos(bottom)) graphregion(color(white) margin(5 5 0 0)) bgcolor(white) legend(rows(2) region(lstyle(none)))
graph save margins_plot_model7.gph, replace

***Trust

*Model 8 - DV: Trust, IV: full, interaction Governor partisanship
clear
use data_for_replication_models_dec2023, replace
tab info_who_dum
logit info_who_dum ib6.pol_idea2##i.gov_dem_dummy ib5.solv_intrnlprobs i.region2 i.geo_scope lost_tax, or  
outreg2 using models_interactive_results.doc, append ctitle(Model 8) dec(2)
margins, at(gov_dem_dummy=(0(1)1) pol_idea2=(2, 6)) vsquish post
outreg2 using margins_interactive_gov.doc, append ctitle(Model 8) dec(2) ci
marginsplot, ///
plot1opts(msymbol(D) mcolor("green") lcolor("green") lpattern(dash)) ///
ci1opt(lcolor(green)) ///
plot2opts(msymbol(O) mcolor("maroon")  lcolor("maroon") lpattern(dash)) ///
ci2opt(lcolor("maroon")) ///
 aspect(1) ytitle("Predicted Probability") xtitle("Governor Partisanship") ylab(0(.2)1) title("B. Trust of WHO", pos(11) margin(b=4)) legend(pos(bottom)) graphregion(color(white) margin(5 5 0 0)) bgcolor(white) legend(rows(2) region(lstyle(none)))
graph save margins_plot_model8.gph, replace

*Model 9 - DV: Trust, IV: full, interaction Trump vote share
clear
use data_for_replication_models_dec2023, replace
logit info_who_dum ib6.pol_idea2##c.trump_vote_prop ib5.solv_intrnlprobs i.region2 i.geo_scope lost_tax, or  
outreg2 using models_interactive_results.doc, append ctitle(Model 9) dec(2)
margins, at(trump_vote_prop=(.3(.1).7) pol_idea2=(2, 6)) vsquish post
outreg2 using margins_interactive_trump.doc, append ctitle(Model 9) dec(2) ci
marginsplot, ///
plot1opts(lcolor(green)) ///
ci1opt(fcolor(green%15) lcolor(green%15) lwidth(0)) ///
plot2opts(lcolor(maroon)) ///
ci2opt(fcolor(maroon%15) lcolor(maroon%15) lwidth(0)) ///
recast(line) recastci(rarea) aspect(1) ytitle("Predicted Probability") xtitle("Trump Vote Share") title(" ", pos(11) margin(b=4))  legend(pos(bottom)) graphregion(color(white) margin(5 5 0 0)) bgcolor(white) legend(rows(2) region(lstyle(none)))
graph save margins_plot_model9.gph, replace

*Model 10 - DV: Trust, IV: full, interaction Governor trust
clear
use data_for_replication_models_dec2023, replace
logit info_who_dum ib6.pol_idea2##i.info_govnr_dum ib5.solv_intrnlprobs i.region2 i.geo_scope lost_tax, or  
outreg2 using models_interactive_results.doc, append ctitle(Model 10) dec(2)
margins, at(info_govnr_dum=(0(1)1) pol_idea2=(2, 6)) vsquish post
outreg2 using margins_interactive_govtrust.doc, append ctitle(Model 10) dec(2) ci
marginsplot, ///
plot1opts(msymbol(D) mcolor("green") lcolor("green") lpattern(dash)) ///
ci1opt(lcolor(green)) ///
plot2opts(msymbol(O) mcolor("maroon")  lcolor("maroon") lpattern(dash)) ///
ci2opt(lcolor("maroon")) ///
aspect(1) ytitle("Predicted Probability") ylab(0(.2)1) xtitle("Governor Trust") title(" ", pos(11) margin(b=4))  legend(pos(bottom)) graphregion(color(white) margin(5 5 0 0)) bgcolor(white) legend(rows(2) region(lstyle(none)))
graph save margins_plot_model10.gph, replace

*******Plots

***Figure 2

coefplot (impact_full, label("Impact of WHO") mcolor(navy) ciopts(lcol(navy%70))) ///
		(trust_full, label("Trust of WHO") mcolor(sienna) ciopts(lcol(sienna%70))), /// 
	hor drop(_cons) xline(0, lpattern(dash) lcolor(red%50)) title("")  /// 
	headings(2.pol_idea2="{bf:Political}" /// 
	1.solv_intrnlprobs="{bf:Take Care of America}" ///
	2.region2="{bf:Region}" /// 
	2.geo_scope="{bf:Geographic Scope}" ///
	lost_tax="{bf:Economic}") aspect(1.75) graphregion(color(white) margin(5 5 0 0)) bgcolor(white) legend(rows(2) region(lstyle(none))) 
	*xtitle("Odds Ratios") 
graph export f2_combined_full_models.png, replace
graph export f2_combined_full_models.pdf, replace	

*****Figure 3
	
graph combine margins_plot_model2.gph margins_plot_model4.gph, graphregion(margin(10 2 2 2) color(white))
graph export f3_combined_full_probabilties.png, replace
graph export f3_combined_full_probabilties.pdf, replace

*****Figure 4 (Interactive Models)

*need grc1leg package installed 

grc1leg margins_plot_model5.gph margins_plot_model6.gph margins_plot_model7.gph margins_plot_model8.gph margins_plot_model9.gph margins_plot_model10.gph, scale(.9) graphregion(margin(5 5 0 0) color(white)) 
graph export f4_combined_interactive_probabilties.png, replace
graph export f4_combined_interactive_probabilties.pdf, replace

